package com.bhy702.generator.builder.factory.codeImpl;

import com.bhy702.generator.builder.TplProperties;
import com.bhy702.generator.builder.util.GenerateUtil;
import com.bhy702.generator.builder.factory.Code;
import org.beetl.core.GroupTemplate;
import org.beetl.core.Template;
import java.io.IOException;

/**
 * @author: brbai
 * @create: 2019-12-14 19:16:14
 * @description:
 */
public class MapperXml implements Code {

    @Override
    public void create(GroupTemplate gt, TplProperties properties, String tplPath) throws IOException {

        String packageName =  properties.getRootPackage()+ ".mapper";
        properties.setParam("packageName",packageName);

        Template t = gt.getTemplate(tplPath);
        t.binding("props", properties);

        //与mapper接口同文件夹，存放在/java下
        //GenerateUtil.createFile(t,System.getProperty("user.dir") + "/src/main/java/" + packageName
        //.replace(".", "/") + "/" + properties.getClassName() + "Mapper.xml");

        //不与mapper同文件夹，存放在resources下
        GenerateUtil.createFile(t,properties.getBasePath() + "/main/resources/mapper/"
                + properties.getClassName() + "Mapper.xml");
    }

}
